//////////////////////////////////////////////////////////////////////////////
//       Copyright (c) 2003 - RealTime Gaming.  All rights reserved.        //
//////////////////////////////////////////////////////////////////////////////

#ifndef KEYWORDSUBSTITUTOR_H
#define KEYWORDSUBSTITUTOR_H

//////////////////////////////////////////////////////////////////////////////
// Includes
//////////////////////////////////////////////////////////////////////////////
#include "lib.h"
#include "ustring.h"
#include "hashtable.h"
#include "list.h"
#include "LocaleFormatter.h"

//////////////////////////////////////////////////////////////////////////////
// Declare Namespace
//////////////////////////////////////////////////////////////////////////////
namespace Library
{

//////////////////////////////////////////////////////////////////////////////
/// KeywordSubstitutor class. Maintains list of keywords and values and
///  performs substitution of those keywords in strings.
//////////////////////////////////////////////////////////////////////////////
class PLIBEXP KeywordSubstitutor
{
    ////////////////////////////////
    // Internal string cache object
    ////////////////////////////////
    class PLIBEXP StringCache
    {
    public:
        StringCache();
        ~StringCache();

        String* FindString( const String& sCacheName );
        String* AddToCache( const String& sCacheName, const String& string );
        bool8   DirtyString( const String& sCacheName );

        bool8 SetKeywordToString( const String& sKeyword, const String& sCacheName );
        bool8 KeywordValueChanged( const String& sKeyword );

    private:
	    HashTable<String*>*           m_pStringCacheTable;
		HashTable< List<String*>* >*  m_pKeywordMatchTable;
    };
    ////////////////////////////////

// Public Interface
public:
	// Construction/Destruction
	KeywordSubstitutor( LocaleFormatter* pFormatter );
	~KeywordSubstitutor();

    // Add methods
    bool8 AddCurrencyValue( const String& sKeyword, int32 nCurrency );
    bool8 AddStringValue( const String& sKeyword, String string );

    // Update methods
    bool8 UpdateCurrencyValue( const String& sKeyword, int32 nCurrency );
    bool8 UpdateStringValue( const String& sKeyword, String string );

    // Remove methods
    bool8 RemoveValue( const String& sKeyword );

    // Main substitution method
	const String& PerformSubstitution( const String& sCacheName, const String& string );

    // Method to allow user to indicate that a string that's stored in the 
    //   cache should be considered "dirty"
    bool8 DirtyCacheString( const String& sCacheName );

// Members
protected:
	HashTable<LocaleValue*>*  m_pTable;	    /**< Internal Hash Table             */
    StringCache               m_oCache;     /**< Internal cache for optimization */
    LocaleFormatter*          m_pFormatter; /**< Pointer to locale formatter     */

private:
    // Hide the default constructor, you must use the one above!
    KeywordSubstitutor() {};
};

}

#endif // #ifndef KEYWORDSUBSTITUTOR_H
